昨天先嘗試利用 HttpClientFactory來建立呼叫外部API,今天來談談要如何實作先前的程式碼吧
先直接上程式碼,這邊選擇用service打包,原因是為了希望之後更方便在外部調用:
至於HashID的部分,暫時先把雜湊值寫死XD
using System.Numerics;
using System.Security.Policy;
using System.Threading.Tasks;
namespace Qpay_Core.Services
{
    public class SignService
    {
        public static string GetSign(string nonce,string data)
        {
            string hashId = GetHashID();
            string sign = data + nonce + hashId;
            return SHA256_Hash.GetSHA256Hash(sign).ToUpper();
        }
        public static string GetHashID()
        {
            //雜湊輸入四個值.........
            string value1 = GetXORencrypt(A1, A2);
            string value2 = GetXORencrypt(B1, B2);
            return (value1 + value2).ToUpper();
        }
        public static string GetXORencrypt(string hex1, string hex2)
        {
            BigInteger dec1 = BigInteger.Parse(hex1, NumberStyles.HexNumber);
            BigInteger dec2 = BigInteger.Parse(hex2, NumberStyles.HexNumber);
            BigInteger result = dec1 ^ dec2;
            string hexResult = result.ToString("X");
            return hexResult;
        }
    }
}